package com.zhuiYun.project.api.homepagefunction.limitedtimepurchase.controller;
import com.zhuiYun.project.api.commoditycomment.entity.CommodityComment;
import com.zhuiYun.project.api.homepagefunction.limitedtimepurchase.service.LimitedTimePurchaseService;
import com.zhuiYun.project.api.seckill.entity.SeckillDto;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @ClassName LimitedTimePurchaseController
 * @Description 限时抢购管理
 * @Author lzk
 * @Date 2023/4/5 9:32
 **/
@RestController
@RequestMapping("/limitedTimePurchase")
@Api(tags = "限时抢购管理")
@Slf4j
@CrossOrigin
public class LimitedTimePurchaseController extends BaseController {
    @Autowired
    LimitedTimePurchaseService limitedTimePurchaseService;
    /**
     * @Author lzk
     * @Description 限时抢购查询秒杀表中商品信息
     * @date 2023/4/5 9:40
     * Return com.zhuiYun.project.common.response.CommonResult
     */
    @GetMapping("/queryFlashKillInformation")
    @ApiOperation(value = "限时抢购查询秒杀表中商品信息")
    public CommonResult queryFlashKillInformation(String commodityName){
        List<SeckillDto> list = limitedTimePurchaseService.queryFlashKillInformation(commodityName);
        log.info("限时抢购查询秒杀表中商品信息"+list);
        return CommonResult.ok(list);
    }
    /**
     * @Author lzk
     * @Description 根据id查询秒杀商品信息计算评论总数量
     * @date 2023/4/6 13:33
     * Return com.zhuiYun.project.common.response.CommonResult
     * @param id
     */
    @GetMapping("/getSeckillListById")
    @ApiOperation(value = "根据id查询秒杀商品信息")
    public CommonResult getSeckillListById(Integer id){
        SeckillDto seckillDto = limitedTimePurchaseService.getSeckillListById(id);
        log.info("根据id查询秒杀信息"+seckillDto);
        return CommonResult.ok(seckillDto);
    }
    /**
     * @Author lzk
     * @Description 计算评论总数量
     * @date 2023/4/7 11:23
     * Return com.zhuiYun.project.api.commoditycomment.entity.CommodityComment
     * @param cid
     */
    @GetMapping("/calculateTheTotalNumberOfComments")
    @ApiOperation(value = "计算评论总数量")
    public CommonResult calculateTheTotalNumberOfComments(Integer cid){
        CommodityComment commodityComment = limitedTimePurchaseService.calculateTheTotalNumberOfComments(cid);
        log.info("计算评论总数量"+commodityComment);
        return CommonResult.ok(commodityComment);
    }
    /**
     *
     * @Author lzk
     * @Description 查询所有评论
     * @date 2023/4/7 11:58
     * Return com.zhuiYun.project.common.response.CommonResult
     * @param cid
     */
    @GetMapping("/queryAllComments")
    @ApiOperation(value = "查询所有评论")
    public CommonResult queryAllComments(Integer cid){
        List<CommodityComment> commodityCommentList = limitedTimePurchaseService.queryAllComments(cid);
        log.info("查询所有评论"+commodityCommentList);
        return CommonResult.ok(commodityCommentList);
    }
    /**
     *
     * @Author lzk
     * @Description 计算购物车数量
     * @date 2023/4/7 16:37
     * Return com.zhuiYun.project.common.response.CommonResult
     */
    @GetMapping("/calculateTheNumberOfShoppingCarts")
    @ApiOperation(value = "计算购物车数量")
    public CommonResult calculateTheNumberOfShoppingCarts(Integer userId){
        Integer appletShoppingCartEntities = limitedTimePurchaseService.calculateTheNumberOfShoppingCarts(userId);
        log.info("计算购物车数量"+appletShoppingCartEntities);
        return CommonResult.ok(appletShoppingCartEntities);
    }
    /** 
     * 
     * @Author lzk
     * @Description 根据cid查询秒杀和商品信息
     * @date 2023/4/9 19:18
     * Return com.zhuiYun.project.common.response.CommonResult
     * @param cid
     */
    @GetMapping("/getSeckillListByCid")
    @ApiOperation(value = "根据cid查询秒杀和商品信息")
    public CommonResult getSeckillListByCid(Integer cid){
        SeckillDto seckillDtoList = limitedTimePurchaseService.getSeckillListByCid(cid);
        log.info("根据cid查询秒杀和商品信息"+seckillDtoList);
        return CommonResult.ok(seckillDtoList);
    }
}
